package com.ywl.designpattern.singleton.type7;

/**
 * @author yuwl
 * @description
 * @since 2024-02-29 10:36
 */
public class Singleton {

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                SingletonEnum instance = SingletonEnum.INSTANCE;
                System.out.println(Thread.currentThread().getName() + ", instance = " + instance);
                System.out.println(Thread.currentThread().getName() + ", instance.hashCode() = " + instance.hashCode());
            }).start();
        }
    }
}

enum SingletonEnum {
    INSTANCE;

    public void doSomething() {
        // 业务逻辑
    }
}
